package com.cbs.android.function.capture.sample;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import com.cbs.android.component.application.activity.CBSActivity;
import com.cbs.android.component.toast.Toast;
import com.cbs.android.function.capture.CaptureFunction;
import com.cbs.android.function.capture.CaptureHandler;
import com.cbs.android.function.imagecrop.ImageCropFunction;
import com.cbs.android.function.imagecrop.ImageCropHandler;

public class MainActivity extends CBSActivity {
    private static final String TAG = MainActivity.class.getName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toast.init(this);
    }

    public void picture(View view) {
        CaptureFunction.startImageCapture(this, new CaptureHandler() {
            @Override
            public void onCaptureSuccess(int requestCode, Intent intent, Uri result) {
                ImageCropFunction.start(MainActivity.this, result, new ImageCropHandler() {
                    @Override
                    public void onCropSuccess(int i, Intent intent, Uri uri) {
                        Toast.show(uri.getPath());
                    }

                    @Override
                    public void onCancel(int i, Intent intent) {
                        Toast.show("crop cancel");
                    }
                });
            }

            @Override
            public void onCancel(int i, Intent intent) {
                Toast.show("cancel");
            }
        });
    }

    public void video(View view) {
        CaptureFunction.startVideoCapture(this, new CaptureHandler() {
            @Override
            public void onCaptureSuccess(int requestCode, Intent intent, Uri result) {
                Toast.show(result.getPath());
            }

            @Override
            public void onCancel(int i, Intent intent) {
                Toast.show("cancel");
            }
        });
    }

    public void videoCustom(View view) {
        CaptureFunction.startVideoCapture(this, 5, "测试abc测试abc测试abc测试abc测试abc测试abc测试abc测试abc测试abc测试abc测试abc", new CaptureHandler() {
            @Override
            public void onCaptureSuccess(int requestCode, Intent intent, Uri result) {
                Toast.show(result.getPath());
            }

            @Override
            public void onCancel(int i, Intent intent) {
                Toast.show("cancel");
            }
        });
    }
}
